package com.wuyan.locationdog.view

import android.content.Context
import android.view.Gravity
import android.view.View
import com.arcsoft.commonbase.R
import com.arcsoft.commonbase.constant.Constants
import com.arcsoft.commonbase.databinding.DialogAgreePrivacyBinding
import com.arcsoft.commonbase.net.ApiService
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.SpanUtils
import com.wuyan.locationdog.ui.X5WebActivity
import razerdp.basepopup.BasePopupWindow


class AgreePrivacyDialog(context: Context,agree:()->Unit) : BasePopupWindow(context) {

    var mBinding: DialogAgreePrivacyBinding? = null

    override fun onViewCreated(contentView: View) {
        mBinding = DialogAgreePrivacyBinding.bind(contentView)
    }

    init {
        setContentView(R.layout.dialog_agree_privacy)
        setClipChildren(false)
        setBackPressEnable(false)
        setOutSideDismiss(false)
        popupGravity = Gravity.CENTER

        mBinding?.apply {
            SpanUtils.with(tvProtocol)
                .append("为了更好的保障您的合法权益，请阅读并同意一下协议")
                .append("《用户协议》")
                .setForegroundColor(ColorUtils.getColor(R.color.text_color_selected))
                .setClickSpan(ColorUtils.getColor(R.color.text_color_selected), false) {
                    X5WebActivity.startAction(ActivityUtils.getTopActivity(), ApiService.BASE_URL+"html/userAgreement.html")
                }
                .append(" ")
                .append("《隐私协议》")
                .setForegroundColor(ColorUtils.getColor(R.color.text_color_selected))
                .setClickSpan(ColorUtils.getColor(R.color.text_color_selected), false) {
                    X5WebActivity.startAction(ActivityUtils.getTopActivity(),ApiService.BASE_URL+"html/privacyAgreement.html")
                }
                .create()

            btnSure.setOnClickListener {
                SPUtils.getInstance().put(Constants.SP_IS_AGREE_PRIVACY, true)
                dismiss()
                agree.invoke()
            }
            btnExit.setOnClickListener {
                AppUtils.exitApp()
            }
        }
    }
}

